package minov.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * This class is for arguments that have file names as their parameters.
 *
 */
public class FileArgument extends MultipleValueArgument<String>  {

   /**
    * Constructs argument that parses string values that are used as file names.<br>
    * Example:
    * 
    * <pre>
    * fileArgument = new FileArgument(&quot;o&quot;, &quot;output&quot;, null)
    * </pre>
    * 
    * @param [in] shortName
    *           argument shortcut
    * @param [in] fullName
    *           full name of argument
    * @param [in] defaultValues
    *           default value/values, if no argument was parsed
    */
    public FileArgument(String shortName, String fullName, String... defaultValues) {
      super(shortName, fullName, defaultValues);

   }

    /**
     * Function for processing one argument. Called by the parser.
     * @param [in] text value to be processed
     * @return processed value
     */
   @Override
   public String parseOneArgument(String text) throws Exception {
      return text;
   }

   private static final String BAD_FILE_FORMAT_STRING =
         "File %s does not match file format.";


   private static final Pattern _validationRegexp = Pattern.compile("[a-zA-Z0-9\\-_]+");

   /**
    * Function for validating one argument value.
    * @param [in] value value to be validated
    * @return ValidationResult object with the result
    */
   @Override
   public ValidationResult validateValue(String value) {
      
      Matcher matcher = _validationRegexp.matcher(value);
      if (matcher.find()==false) {
         return ValidationResult.createInvalidResponse(String.format(
               BAD_FILE_FORMAT_STRING, value));
      }
      return ValidationResult.createValidResponse();
   }

   /**
    * Function for returning specific array type for this class. 
    * @return array of the specific type
    */
   @Override
   String[] getGenericArray() {
      return new String[0];
   }
   
}
